/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controladores;

import Interfaces.ICtrlNotificaciones;
import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *
 * @author Sebas
 */
public class CtrlNotificaciones implements ICtrlNotificaciones {
    
    @Override
    public void mandarMail(String mailDest, String asunto, String mensaje) {
        Properties props = new Properties();
        props.setProperty("mail.smtp.host", "smtp.gmail.com");
        props.setProperty("mail.smtp.starttls.enable", "true");
        props.setProperty("mail.smtp.port", "25");
        props.setProperty("mail.smtp.user", "tarea.progaplic@gmail.com");
        props.setProperty("mail.smtp.auth", "true");
        Session session = Session.getInstance(props, null);

        try {
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress("tarea.progaplic@gmail.com"));
            msg.setFrom();
            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(mailDest));
            msg.setSubject(asunto);
            msg.setSentDate(new Date());
            mensaje = "\n\t<table cellspacing=\"0\" cellpadding=\"0\" style=\"border-collapse:collapse;width:620px\"><tbody><tr><td style=\"font-size:16px;font-family:'lucida grande',tahoma,verdana,arial,sans-serif;background:#3b5998;color:#FFFFFF;font-weight:bold;vertical-align:middle;letter-spacing:-0.03em;text-align:left;padding:10px 38px 4px\"><a style=\"text-decoration:none\" href=\"http://localhost:8084/RED/\" target=\"_blank\"><span style=\"background:#3b5998;color:#FFFFFF;font-weight:bold;font-family:'lucida grande',tahoma,verdana,arial,sans-serif;vertical-align:middle;font-size:16px;letter-spacing:-0.03em;text-align:left\">redbuck</span></a></td></tr></tbody></table>"+mensaje;
            msg.setContent(mensaje , "text/html");
            Transport t = session.getTransport("smtp");
            t.connect("tarea.progaplic@gmail.com", "tarea234");
            t.sendMessage(msg, msg.getAllRecipients());
        } catch (MessagingException mex) {
            System.out.println("send failed, exception: " + mex);
        }
    }
}
